package com.swyc.osschat.Common.Util.Object;


import org.apache.commons.lang.StringUtils;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Objects;

/**
 * @author yanyipeng.ykw@foxmail.com
 */
public class StringUtil extends StringUtils {

    public static final String STRING_EMPTY = "";

    private static final StringBuilder BUILDER = new StringBuilder();

    public static boolean isEmpty(Object obj){
        return obj == null || "".equals(obj.toString());
    }

    public static String nullToStringDefault(Object obj){
        return isEmpty(obj)? STRING_EMPTY : obj.toString();
    }

    public static String nullToStringDefault(Object obj,String defaultStr){
        return isEmpty(obj)? defaultStr : obj.toString();
    }

    private StringUtil(){}

    private static final SimpleDateFormat FORMAT = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");

    public static String getDateString(Date date){
        return FORMAT.format(date);
    }

    public static String getDateString(){
        return getDateString(new Date());
    }

    public static boolean isNotEmpty(Object obj){
        return !isEmpty(obj);
    }

    public static String nvl(String instr) {
        return nvl(instr, STRING_EMPTY);
    }

    public static String nvl(Object str) {
        return nvl(Objects.isNull(str) ? null : str.toString());
    }

    public static String nvl(String instr, String defaultValue) {
        return instr == null || "".equals(instr) ? defaultValue : instr;
    }

}
